//
//  PlatformResult
//
//  Created by Caue W. on 2011-03-30.
//  Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
package time.compiler.types.runtime;
import time.Errors;

@:abstract class PlatformResult 
{
	
	/**
	* Depending on the data platform, descending will either add a descending operator to the
	* prefix, or will actually push the descending object to the stack
	**/
	public function push(to:String) : Void
	{
		throw NotImplemented;
	}
	
	/**
	* go back to the parent
	**/
	public function pop() : Void
	{
		throw NotImplemented;
	}
	
	/**
	*  Gets the query result whose field is "field"
	*  This -will not- work on all database platforms, and should not be used directly
	**/
	private function get(field:String) : Dynamic
	{
		throw NotImplemented;
	}
	
	public function getString(field:String, ?max:Null<Int>) : String
	{
		var s:String = get(field);
		return s.substr(0, max);
	}
	
	public function getDate(field:String) : Date
	{
		return get(field);
	}
	
	public function getInt(field:String) : Int
	{
		return get(field);
	}
	
	public function getInt32(field:String) : haxe.Int32
	{
		return haxe.Int32.ofInt(getInt(field));
	}
	
	public function getInt64(field:String) : haxe.Int64
	{
		throw NotImplemented;
	}
	
	public function getBool(field:String) : Bool
	{
		throw NotImplemented;
	}
	
	public function getDouble(field:String) : Float
	{
		throw NotImplemented;
	}
	
	public function getBigInt(field:String) : time.types.complex.BigInt
	{
		push(field);
		var s = getString("__s");
		if (getBool("positive"))
			s = "-" + s;
		var ret = BigInt.fromString(s);
		pop();
		
		return ret;
	}
	
	public function getDecimal(field:String) : time.types.complex.Decimal
	{
		push(field);
		
		var num = getBigInt("numeral");
		var fract = getBigInt("fractional");
		
		var ret = time.types.complex.Decimal.fromBigInts(num, fract);
		
		pop();
		
		return ret;
	}
	
	public function getBlob(field:String, ?max:Null<Int>) : haxe.io.Bytes
	{
		throw NotImplemented;
	}
	
	public function unwrapToMany<T>(field:String) : Array<T>
	{
		throw NotImplemented;
	}
	
	
}